package cz.apnetis.gwt.client;

import java.util.HashMap;
import java.util.Map;

/** Converter value to string<br />
 * <br />
 * value.equals(convertFromString(convertToString(value));<br />
 * <br />
 * @author Lukas "benzin" Benda <a href="mailto:luk.benda@gmail.com">luk.benda@gmail.com</a>
 * @param <E> object which convert value from and to string
 */
public interface StringConverter<E> {

  /** Default converter */
  public static final Map<Class<?>, StringConverter<?>> DEFAULT_CONVERTERS = new HashMap<Class<?>, StringConverter<?>>();

  /** Method which convert value to string representation
   * @param value value can be null
   * @return return null when value is null
   */
  String valueToString(E value);

  /** Convert string to value
   * @param value transform text to value
   * @return return null if value is null.
   */
  E stringToValue(String value);
}
